﻿using SqlSugar;

namespace Rabbit3.Api.Common
{
	public static class SqlSugarSetup
	{
		/// <summary>
		/// 注册 SqlSugar 到 DI 容器
		/// </summary>
		public static void AddSqlSugar(this IServiceCollection services, string connectionString)
		{
			services.AddSingleton<ISqlSugarClient>(new SqlSugarClient(new ConnectionConfig
			{
				ConnectionString  = connectionString,
				DbType = DbType.MySql,
				IsAutoCloseConnection = true,
				InitKeyType = InitKeyType.Attribute // 从实体属性读取主键/自增配置
			}));
		}
	}
}
